from ..data_structures.base_structures import *
from ..config.config import *

class PPEngineComponents(Enum):

    ModifiyCellWithWater = 'modify_cell_with_water'
    ModifiyCellWithVegetation = 'modify_cell_with_vegetation'
    ModifiyCellWithRoad = 'modify_cell_with_road'
    ModifiyCellWithElevation = 'modify_cell_with_elevation'
    ModifiyCellWithCv = 'modify_cell_with_cv'
    ModifiyCellWithRelief = 'modify_cell_with_relief'
    ModifiyCellWithRoughness = 'modify_cell_with_roughness'
    ModifiyCellWithSlope = 'modify_cell_with_slope'
    ModifiyCellWithCurvature = 'modify_cell_with_curvature'
    ModifiyCellWithGeology = 'modify_cell_with_geology'
    ModifiyCellWithBuilding = 'modify_cell_with_building'
    ModifiyCellWithSoil = 'modify_cell_with_soil'
    ModifiyCellWithTime = 'modify_cell_with_time'
    ModifiyCellWithConsumption = 'modify_cell_with_consumption'
    ModifiyCellWithCrypticity = 'modify_cell_with_crypticity'

    def modify_cell_with_road(neighbor_cell: HexCell):
        """考虑道路对cell通行能力的影响"""
        if neighbor_cell.road_type == RoadType.NORMALWAY:
            # 有路就给奖励
            # neighbor_cell.g_increment *= 0.1
            neighbor_cell.g *= 0.1

    def modify_cell_with_cv(neighbor_cell: HexCell):
        # 高程变异系数
        if not PPConfig.has_config('DemAttribute.ElevationCoefficientOfVariation'):
            raise Exception("未配置高程变异系数的阈值")
        cv_value = PPConfig.get_config('DemAttribute.ElevationCoefficientOfVariation')
        if cv_value is None or cv_value == "":
            raise Exception("未配置高程变异系数的阈值")
        if not neighbor_cell.has_attribute(DemAttribute.ElevationCoefficientOfVariation):
            pass
        elif neighbor_cell.get_attribute(DemAttribute.ElevationCoefficientOfVariation).get_value() > cv_value:
            neighbor_cell.rejected = True
            return

    def modify_cell_with_roughness(neighbor_cell: HexCell):
        # 地形粗糙度
        if not PPConfig.has_config('DemAttribute.Roughness'):
            raise Exception("未配置地形粗糙度的阈值")
        roughness_value = PPConfig.get_config('DemAttribute.Roughness')
        if roughness_value is None or roughness_value == "":
            raise Exception("未配置地形粗糙度的阈值")
        if not neighbor_cell.has_attribute(DemAttribute.Roughness):
            pass
        elif neighbor_cell.get_attribute(DemAttribute.Roughness).get_value() > roughness_value:
            neighbor_cell.rejected = True
            return

    def modify_cell_with_curvature(neighbor_cell: HexCell):
        # 曲率
        if not PPConfig.has_config('DemAttribute.Curvature'):
            raise Exception("未配置曲率的阈值")
        curvature_value = PPConfig.get_config('DemAttribute.Curvature')
        if curvature_value is None or curvature_value == "":
            raise Exception("未配置曲率的阈值")
        if not neighbor_cell.has_attribute(DemAttribute.Curvature):
            pass
        elif abs(neighbor_cell.get_attribute(DemAttribute.Curvature).get_value()) > curvature_value:
            neighbor_cell.rejected = True
            return

    def modify_cell_with_time(neighbor_cell: HexCell):
        """考虑时间因子对通行能力的影响"""
        try:
            time_factor = neighbor_cell.get_attribute(Weight).get_sub_attribute(TimeWeight).get_value()
        except Exception as e:
            raise Exception("还未分析时间因子")
        neighbor_cell.g += time_factor

    def modify_cell_with_consumption(neighbor_cell: HexCell):
        """考虑消耗因子对通行能力的影响"""
        try:
            consumption_factor = neighbor_cell.get_attribute(Weight).get_sub_attribute(ConsumptionWeight).get_value()
        except Exception as e:
            raise Exception("还未分析能耗因子")
        neighbor_cell.g += consumption_factor

    def modify_cell_with_crypticity(neighbor_cell: HexCell):
        if not neighbor_cell.has_attribute(Crypticity):
            neighbor_cell.rejected = True




